import { sequelize} from '@/modules/BaseDao';
import { Orderinfo, OrderDetail } from './entity';
class OrdAndOrdDetailDao{
  static ordAndOrdDetailDao: OrdAndOrdDetailDao = new OrdAndOrdDetailDao()

  async addOrderinfo(orderinfo:Orderinfo): Promise<[any,any]>{
    const ordSql=`insert into orderinfo(ordertime,customerid,orderstatus)
    values('${orderinfo.ordertime},${orderinfo.customerid},${orderinfo.orderstatus})`
    return await sequelize.query(ordSql);
  }

  async addOrderDetail(orderDetail:OrderDetail): Promise<[any,any]>{
    const ordSql=`insert into orderdetail(bookname,bookprice,bookpicname,purcharsenum,orderid)
    values('${orderDetail.bookname},${orderDetail.bookprice},${orderDetail.bookpicname},${orderDetail.purcharsenum},${orderDetail.orderid}))`
    return await sequelize.query(ordSql);
  }
  async findCurUsrordAndordDetail(customerid:string): Promise<[any,any]>{
    const sql = `SELECT oi.orderid,oi.ordertime,oi.customerid,oi.orderstatus,
    odi.bookname,odi.bookpicname,odi.bookpicname,odi.orderdetailid,odi.purcharsenum
    FROM orderinfp oi inner join dangdang.orderdetail odi
    on oi.orderid=odi.orderid and oi.customerid=${customerid}`;
    return sequelize.query(sql);
  }
  // 倒计时也要用
  uptOrdStatusByOrdId(orderid:number,orderstatus:number):Promise<[any,any]>{
    const uptOrdStatusSql= `update orderinfo set orderstatus=${orderstatus} where orderid=${orderid}`;
    return sequelize.query(uptOrdStatusSql);
  }
}
export default OrdAndOrdDetailDao.ordAndOrdDetailDao
